package com.apache.bid.service.plugins;

import org.apache.log4j.Logger;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.entity.BidPrintTemplate;
import com.apache.bid.manager.BidPrintTemplateManager;
import com.apache.cache.util.Validator;

/**
 * description:  根据templateId获取BidPrintTemplate
 * @author ljshi 创建时间：2016-5-17  
 * 
 */
public class BidPrintTemplateEntityPlugin implements PluginConnector {

	private Logger logger = Logger.getLogger(BidPrintTemplateEntityPlugin.class);
	private BidPrintTemplateManager bidPrintTemplateManager;

	@Override
	public Object execute(ParamsVo vo) throws Exception {
		ResultEntity result = new ResultEntity();
		result.setResult("true");
		try {
			String templateId = String.valueOf(vo.getParams("templateId"));
			if (Validator.isNull(templateId)) {
				result.setResult("false");
				result.setMessage("缺少参数！");
				return result;
			}
			ParamsVo<BidPrintTemplate> tempVo = new ParamsVo<BidPrintTemplate>();
			tempVo.setInfoId(templateId);
			BidPrintTemplate temp = (BidPrintTemplate) bidPrintTemplateManager.getInfoById(tempVo);

			if (null == temp) {
				result.setResult("false");
				result.setMessage("查询失败！");
			} else {
				result.setEntity(temp);
				result.setMessage("查询成功！");
			}
		} catch (Exception e) {
			result.setResult("false");
			result.setMessage("查询错误！");
			logger.error("查询单个template对象错误！" + e.getMessage());
		}
		return result;
	}

	public void setBidPrintTemplateManager(BidPrintTemplateManager bidPrintTemplateManager) {
		this.bidPrintTemplateManager = bidPrintTemplateManager;
	}

}
